/**
 *   @file Thread.h
 */
#ifndef _THREAD_H_
#define _THREAD_H_

#include "../common/BaseObject.h"
#include "../util/FuncPtrT.h"
#include "../text/CFString.h"

namespace cppflib
{

namespace threading
{

//! thread function entry point
typedef util::FuncPtr1T<int, ptr_t> ThreadEntryPoint;

class ThreadInfo;

/**
 *  A simple threading class
 */
class _DLLAPI Thread : public BaseObject
{
private:
    ThreadInfo * pThreadInfo;
   
public:

    //! If use this ctor, override and implement 'Run' member function
    Thread(void);
    //! If use this ctor, just ignore 'Run'
    explicit Thread(const ThreadEntryPoint &threadEntry);
    virtual ~Thread(void);
    
    bool Start(ptr_t pParam);
    ptr_t Join(void);
    bool IsAlive(void);
    ptr_t GetId(void);

    PUBLIC void Sleep(int sleepTime);
    PUBLIC ptr_t GetCurrentThreadId(void);

    PUBLIC BaseObject * GetNamedData(const CFString &key);
    PUBLIC void SetNamedData(const CFString &key, BaseObject *pData);
    PUBLIC bool RemoveNamedData(const CFString &key);

    virtual int Run(ptr_t pParam);
  
};


} // end of namespace threading


} // end of namespace cppflib




#endif
